package org.jeecg.common.util;

import java.io.*;


public class FileUtil {
    private static final String prefix = "classpath:";

    public static String read(String path){
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
//            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\code\\color.txt"), "UTF-8"));
            return  in.readLine();
        }catch (Exception e){
            return "";
        }
    }

    public static Boolean write(String folderPath , String fileName ,String str) {
        try {

            String path = folderPath+ fileName;

            File folder = new File(folderPath);
            if (!folder.exists()) {
                folder.mkdirs();
            }
            File file=new File(path);
            if(!file.exists()) {
                file.createNewFile();
            }

            //写入相应的文件
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"));
//            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("d:\\code\\color.txt"), "UTF-8"));
            out.write(str);
            //清楚缓存
            out.flush();
            out.close();
        } catch (Exception e) {
            return false;
        }
        return true;
    }

}
